package org.trackcore.handler;

import org.springframework.stereotype.Component;
import org.trackcore.model.entity.PerformanceFetch;
import org.trackcore.service.PerformanceFetchService;
import org.trackcore.utils.DataUtils;

import javax.xml.ws.handler.Handler;
import java.util.Map;

@Component
public class PerformanceFetchHandler implements DataHandler {
    private final PerformanceFetchService service;

    public PerformanceFetchHandler(PerformanceFetchService service) {
        this.service = service;
    }

    @Override
    public String getHandlerKey() {
        return "performance_fetch"; // 对应前端subType
    }

    @Override
    public void handle(Map<String, Object> data, String logId) {
        PerformanceFetch fetch = PerformanceFetch.builder()
                .logId(logId)
                .url(DataUtils.getString(data, "url"))
                .method(DataUtils.getString(data, "method", "GET"))
                .startTime(DataUtils.getDouble(data, "startTime"))
                .build();

        service.save(fetch);
    }
}
